{% extends "common/layout_main.html" %}
{% block content %}
<div class="row  border-bottom">
    <div class="col-lg-12">
        <div class="tab_title">
            <ul class="nav nav-pills">
                <li class="current">
                    <a href="{{ url_for('account_page.index') }}"><i class="fa fa-angle-double-left fa-lg" aria-hidden="true"></i> 账户列表</a>
                </li>
            </ul>
        </div>
    </div>
</div>
<div class="row m-t  wrap_account_edit">
	<div class="col-lg-12">
		<h2 class="text-center">账号设置</h2>
		<div class="form-horizontal m-t m-b">
			<div class="form-group">
				<label class="col-lg-2 control-label">昵称:</label>
				<div class="col-lg-10">
					<input type="text" name="nickname" class="form-control" placeholder="请输入昵称~~" value="{{ user.nickname }}">
				</div>
			</div>
			<div class="hr-line-dashed"></div>
			<div class="form-group">
				<label class="col-lg-2 control-label">性别:</label>
				<div class="col-lg-10">
					<input type="text" name="sex" class="form-control" placeholder="请输入性别~~" value="{% if user.sex == 1 %}男{% else %}女{% endif %}">
				</div>
			</div>
			<div class="hr-line-dashed"></div>
			<div class="form-group">
				<label class="col-lg-2 control-label">手机:</label>
				<div class="col-lg-10">
					<input type="text" name="mobile" class="form-control" placeholder="请输入手机~~" value="{{ user.mobile }}">
				</div>
			</div>
			<div class="hr-line-dashed"></div>
			<div class="form-group">
				<label class="col-lg-2 control-label">邮箱:</label>
				<div class="col-lg-10">
					<input type="text" name="email" class="form-control" placeholder="请输入邮箱~~" value="{{ user.email }}">
				</div>
			</div>
			<div class="hr-line-dashed"></div>
			<div class="form-group">
				<label class="col-lg-2 control-label">登录账号:</label>
				<div class="col-lg-10">
					<input type="text" name="login_name" class="form-control" autocomplete="off" placeholder="请输入登录账号(11位手机号)~~" readonly value="{{ user.login_name }}">
				</div>
			</div>
			<div class="hr-line-dashed"></div>
			<div class="form-group">
				<label class="col-lg-2 control-label">登录密码:</label>
				<div class="col-lg-10">
					<input type="password" name="login_pwd" class="form-control" autocomplete="new-password" placeholder="请输入6-16位新密码(可以不修改密码提交)~~" value="">
				</div>
			</div>
			<div class="hr-line-dashed"></div>
			<div class="form-group">
				<div class="col-lg-4 col-lg-offset-2">
                    <input type="hidden" name="id" value="0">
					<button class="btn btn-w-m btn-outline btn-primary save">保存</button>
				</div>
			</div>
		</div>
	</div>
</div>

<script src="/static/plugins/jquery-2.1.1.js"></script>
<script src="/static/bootstrap/bootstrap.min.js"></script>
<script src="/static/plugins/layer/layer.js"></script>
<script src="/static/js/common.js"></script>
{% endblock %}
{% block js %}
<script>
	var account_edit = {
		init:function(){
			this.eventBind()
		},
        isPhone:function(phones){
            var myreg = /^[1][3,4,5,7,8,9][0-9]{9}$/;
            return myreg.test(phones)
        },
		eventBind:function(){
            $(".wrap_account_edit .save").click(function(){
                var nickname_target = $(".wrap_account_edit input[name=nickname]");
                var sex_target = $(".wrap_account_edit input[name=sex]");
                var mobile_target = $(".wrap_account_edit input[name=mobile]");
                var email_target = $(".wrap_account_edit input[name=email]");
                var login_pwd_target = $(".wrap_account_edit input[name=login_pwd]");
                var nickname = nickname_target.val();
                var sex = sex_target.val();
                var mobile = mobile_target.val();
                var email = email_target.val();
                var login_pwd = login_pwd_target.val();

                if (nickname == "" || nickname.length < 1){
                    common_ops.tip("请输入正确的昵称！",nickname_target)
                    return ;
                }
                if (sex == "" || sex.length != 1){
                    common_ops.tip("请输入正确的性别！",sex_target)
                    return ;
                }
                if (mobile == "" || !account_edit.isPhone(mobile)){
                    common_ops.tip("请输入正确的手机号！",mobile_target)
                    return ;
                }
                if (email == "" || email.length < 6 ){
                    common_ops.tip("请输入正确的邮箱！",email_target)
                    return ;
                }
                data = {
                    "nickname":nickname,
                    "sex":sex,
                    "mobile":mobile,
                    "email":email,
                    "login_pwd":login_pwd
                }
                $.ajax({
                    url:"/account/edit?id={{ user.uid }}",
                    type:"POST",
                    data:data,
                    dataType:"json",
                    success:function(res){
                        var callback = null
                        if(res.code == 200){
                            callback = function(){
                                window.location.href = "/account/index"
                            }
                            common_ops.alert(res.msg,callback)
                        }
                        if(res.code == -1){
                            common_ops.alert(res.msg)
                        }
                    }
                })

            });
		}
	}
    $(document).ready(function(){
        account_edit.init();
    })

</script>
{% endblock %}
